﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EmoneyWeiXinEntity;
using EmoneyWeiXinBLL;
using EmoneyWeiXinCommon;
using EmoneyWeiXin.Filter;
namespace EmoneyWeiXin.Controllers
{
    public class UserLabelManagerController : Controller
    {
        //
        // GET: /UserLabelManager/
  [LoginAuthorizeAttribute]
        public ActionResult Index()
        {
            ViewBag.leftid = int.Parse(Request["leftid"]);
            return View();
        }
        //查询用户组列表
        public string GetUserLabelList()
        {
            var strJson = "";
            var total = 0;
            var pindex = int.Parse(Request["index"]);
            var psize = int.Parse(Request["size"]);
            var weixinid = int.Parse(Request["weixinid"]);
            var list = UserLabelManagerBLL.getUserLabelManagerList(pindex, psize, weixinid, out  total);
            if (list != null)
                strJson = JsonTools.ToJson(list);
            return total + "~" + strJson;
        }
        //根据id查询用户组
        public string GetUserLabelListByID()
        {
            var strJson = "";
            var id = int.Parse(Request["id"]);
            var list = UserLabelManagerBLL.getUserLabelManagerListByID(id);
            if (list != null)
                strJson = JsonTools.ToJson(list);
            return strJson;
        }
        //更新用户组方法
        public string UpdateUserLabel()
        {
            var uid = 0;
            UserEntity us = LoginUserInfo.GetLoginUserCache();
            if (us != null)
                uid = us.id;
            var op = int.Parse(Request["op"]);
            var id = int.Parse(Request["id"]);
            var ire = 0;
            if (op != -1)//编辑操作
            {
                var weixinid = int.Parse(Request["weixinid"]);
                var name = Request["name"];
                var remark = Request["remark"];
                var isvalid = 1;
                var obj = new UserLabelManagerEntity();
                obj.id = id;
                obj.name = name;
                obj.isvalid = isvalid;
                obj.createtime = DateTime.Now;
                obj.updatetime = DateTime.Now;
                obj.remark = remark;
                obj.weixinid = weixinid;
                obj.creator = uid;
                ire = UserLabelManagerBLL.UpdateUserLabelManager(obj);
            }
            else//删除操作
            {
                ire = UserLabelManagerBLL.DeleteUserLabelManager(id);
            }
            return ire.ToString();
        }

    }
}
